const err = require('./error.js')
import sys from './sys.js'

module.exports = {
	auditImages: () => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/auditImgComment', {}, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	userLoginSendSms: obj => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/loginSendSms', obj, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	userLogin: obj => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/login', obj, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	userInfo: () => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/userInfo', {}, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	userLogout: () => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/logout', {}, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	starImages: imgIdList => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/starImage', {local:imgIdList}, true).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	cancelStarImage: imgId=> new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/cancelStarImage', {imgid: imgId}, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	getImgIdList: ()=> new Promise((s, f) => {
		sys.getUrl('https://www.water-crystal.org/WechatApp/Pray/imageIdList').then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),

	getImgDetailList: imgIdList => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/getImages', {
			ids: imgIdList
		}, true).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),

	incImageUpvote: imgId => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/upvoteImage', {
			id: imgId
		}, false).then(s).catch(e => f(err.Net_Access_Failure))
	}),
	
	
	getImageComments: obj => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/getImageComments', obj, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	commentImage: comment => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/commentImage', comment, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),
	
	upvoteImageComment: commentId => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/upvoteImageComment', {cid: commentId}, false).then(res=>s(res.data)).catch(e => f(err.Net_Access_Failure))
	}),

	addPackage: p => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/addPackage', p, true).then(s).catch(e => f(err.Net_Access_Failure))
	}),

	incPackageThanks: pid => new Promise((s, f) =>
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/thankPackage', {
			id: pid
		}, false).then(s).catch(f)
	),

	searchNearestPackage: (gps) => new Promise((s, f) =>
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/searchPackage', {
			nearest: true,
			gps: gps
		}, true).then(res=>s(res.data)).catch(f)
	),

	searchPackageByRegion: (region) => new Promise((s, f) =>
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/searchPackage', {
			nearest: false,
			region: region
		}, true).then(res=>s(res.data)).catch(f)
	),

	getPackageById: pid => new Promise((s, f) => {
		sys.postUrl('https://www.water-crystal.org/WechatApp/Pray/getPackageById', {
			id: pid
		}, false).then(res=>s(res.data)).catch(f)
	}),

	// addStarImage: imgId => new Promise((s, f) => ,
	// 	// stars.add(_(s, f, { imgId: imgId, time: new Date(), rm: false }))
	// ),
	// unstarImage: starId => new Promise((s, f) => stars.doc(starId).update(_(s, f, {
	// 	rm: true
	// }))),
	// getUserStarList: () => new Promise((s, f) => stars.where({
	// 	rm: false
	// }).get(_(s, f))),
	// 
}
